home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / GRAPHICS.SWG / 0113_Pallete Handling.pas < prev    next >
Pascal/Delphi Source File  |  1994-08-24  |  7KB  |  264 lines

  1. { GrafCont initializes the graphics mode and handles pallete fades. }
  2.  
  3. unit GrafCont;
  4.  
  5. interface
  6.  
  7. uses
  8.   Crt, Dos, Graph;
  9.  
  10. type
  11.   Palette256 = array[0..255, 0..2] of Byte;
  12.   Palette16 = array[0..15, 0..2] of Byte;
  13.  
  14. var
  15.   Mode           : byte;
  16.  
  17. procedure Init256VGA;
  18. procedure Init16VGA;
  19. procedure SetVGAPalette256(PalBuf: Palette256);
  20. procedure GetVGAPalette256(var PalBuf: Palette256);
  21. procedure SetVGAPalette16(PalBuf: Palette16);
  22. procedure GetVGAPalette16(var PalBuf: Palette16);
  23. procedure GetRGBPalette(PalNum: integer; var R, G, B: byte);
  24. procedure FadeOutScreen256;
  25. procedure FadeOutScreen16;
  26. procedure FadeInScreen256(PalToMake: Palette256);
  27. procedure FadeInScreen16(PalToMake: Palette16);
  28.  
  29. implementation
  30.  
  31. procedure Init256VGA;
  32.    {This procedure relies on BGI drivers obtained for Pascal.
  33.     You may need to create a new procedure based on your own
  34.     method for turning on the graphics mode.}
  35.  
  36.    var
  37.      graphmode      : integer;
  38.      graphdriver    : integer;
  39.  
  40.    begin
  41.    graphdriver := VGA256Graph;  {Defined as an OBJ}
  42.    graphmode := 0;
  43.    initgraph(graphdriver, graphmode, '');
  44.    end;
  45.  
  46. procedure Init16VGA;
  47.    var
  48.      graphdriver    : integer;
  49.      graphmode      : integer;
  50.  
  51.    begin
  52.    graphdriver := 9;
  53.    graphmode := 2;
  54.    initgraph(graphdriver, graphmode, '');
  55.    end;
  56.  
  57. procedure SetVGAPalette256;
  58. var
  59.   ColorOn : byte;
  60.  
  61. begin
  62.   Port[$3C8] := 0;
  63.   for ColorOn := 0 to 255 do
  64.       begin
  65.       Port[$3C9] := PalBuf[ColorOn, 0];
  66.       Port[$3C9] := PalBuf[ColorOn, 1];
  67.       Port[$3C9] := PalBuf[ColorOn, 2];
  68.       end;
  69. end;
  70.  
  71. procedure GetVGAPalette256;
  72. var
  73.   ColorOn : byte;
  74.  
  75. begin
  76.   Port[$3C8] := 1;
  77.   for ColorOn := 0 to 255 do
  78.       begin
  79.       PalBuf[ColorOn, 0] := Port[$3C9];
  80.       PalBuf[ColorOn, 1] := Port[$3C9];
  81.       PalBuf[ColorOn, 2] := Port[$3C9];
  82.       end;
  83.   PalBuf[0, 0] := 0;
  84.   PalBuf[0, 1] := 0;
  85.   PalBuf[0, 2] := 0;
  86. end;
  87.  
  88. procedure SetVGAPalette16;
  89. var
  90.   ColorOn : byte;
  91.  
  92. begin
  93.   Port[$3C8] := 0;
  94.   for ColorOn := 0 to 15 do
  95.       begin
  96.       Port[$3C9] := PalBuf[ColorOn, 0];
  97.       Port[$3C9] := PalBuf[ColorOn, 1];
  98.       Port[$3C9] := PalBuf[ColorOn, 2];
  99.       end;
  100. end;
  101.  
  102. procedure GetVGAPalette16;
  103. var
  104.   ColorOn : byte;
  105.  
  106. begin
  107.   Port[$3C8] := 1;
  108.   for ColorOn := 0 to 15 do
  109.       begin
  110.       PalBuf[ColorOn, 0] := Port[$3C9];
  111.       PalBuf[ColorOn, 1] := Port[$3C9];
  112.       PalBuf[ColorOn, 2] := Port[$3C9];
  113.       end;
  114.   PalBuf[0, 0] := 0;
  115.   PalBuf[0, 1] := 0;
  116.   PalBuf[0, 2] := 0;
  117. end;
  118.  
  119.  
  120. procedure GetRGBPalette;
  121.  
  122. begin
  123.   Port[$3C8] := PalNum;
  124.   R := Port[$3C9];
  125.   G := Port[$3C9];
  126.   B := Port[$3C9];
  127. end;
  128.  
  129. procedure FadeOutScreen256;
  130.    var
  131.      Count        : word;
  132.      ColorOn      : byte;
  133.      PalToMake    : Palette256;
  134.      PaletteStuff : Palette256;
  135.  
  136.    begin
  137.    GetVGAPalette256(PaletteStuff);
  138.    PalToMake := PaletteStuff;
  139.    for Count := 63 downto 0 do
  140.        begin
  141.        Port[$3C8] := 0;
  142.        PaletteStuff := PalToMake;
  143.        Delay(1);
  144.        for ColorOn := 0 to 255 do
  145.            begin
  146.            PaletteStuff[ColorOn, 0] := (PaletteStuff[ColorOn, 0] * Count) div 63;
  147.            PaletteStuff[ColorOn, 1] := (PaletteStuff[ColorOn, 1] * Count) div 63;
  148.            PaletteStuff[ColorOn, 2] := (PaletteStuff[ColorOn, 2] * Count) div 63;
  149.            Port[$3C9] := PaletteStuff[ColorOn, 0];
  150.            Port[$3C9] := PaletteStuff[ColorOn, 1];
  151.            Port[$3C9] := PaletteStuff[ColorOn, 2];
  152.            end;
  153.        end;
  154.    end;
  155.  
  156. procedure FadeOutText;
  157.    var
  158.      Count        : word;
  159.      ColorOn      : byte;
  160.      PalToMake    : Palette256;
  161.      PaletteStuff : Palette256;
  162.  
  163.    begin
  164.    GetVGAPalette256(PaletteStuff);
  165.    PalToMake := PaletteStuff;
  166.    for Count := 63 downto 0 do
  167.        begin
  168.        Port[$3C8] := 0;
  169.        PaletteStuff := PalToMake;
  170.        Delay(20);
  171.        for ColorOn := 0 to 255 do
  172.            begin
  173.            PaletteStuff[ColorOn, 0] := (PaletteStuff[ColorOn, 0] * Count) div 63;
  174.            PaletteStuff[ColorOn, 1] := (PaletteStuff[ColorOn, 1] * Count) div 63;
  175.            PaletteStuff[ColorOn, 2] := (PaletteStuff[ColorOn, 2] * Count) div 63;
  176.            Port[$3C9] := PaletteStuff[ColorOn, 0];
  177.            Port[$3C9] := PaletteStuff[ColorOn, 1];
  178.            Port[$3C9] := PaletteStuff[ColorOn, 2];
  179.            end;
  180.        end;
  181.    end;
  182.  
  183. procedure FadeInScreen256;
  184.    var
  185.      Count        : byte;
  186.      ColorOn      : byte;
  187.      PaletteStuff : Palette256;
  188.      FastPal      : Palette256;
  189.  
  190.    begin
  191.    GetVGAPalette256(PaletteStuff);
  192.    for Count := 0 to 63 do
  193.        begin
  194.        Port[$3C8] := 0;
  195.        PaletteStuff := PalToMake;
  196.        Delay(1);
  197.        for ColorOn := 0 to 255 do
  198.            begin
  199.            PaletteStuff[ColorOn, 0] := (PaletteStuff[ColorOn, 0] * Count) div 63;
  200.            PaletteStuff[ColorOn, 1] := (PaletteStuff[ColorOn, 1] * Count) div 63;
  201.            PaletteStuff[ColorOn, 2] := (PaletteStuff[ColorOn, 2] * Count) div 63;
  202.            Port[$3C9] := PaletteStuff[ColorOn, 0];
  203.            Port[$3C9] := PaletteStuff[ColorOn, 1];
  204.            Port[$3C9] := PaletteStuff[ColorOn, 2];
  205.            end;
  206.        end;
  207.    end;
  208.  
  209. procedure FadeOutScreen16;
  210.    var
  211.      Count        : word;
  212.      ColorOn      : byte;
  213.      PalToMake    : Palette16;
  214.      PaletteStuff : Palette16;
  215.  
  216.    begin
  217.    GetVGAPalette16(PaletteStuff);
  218.    PalToMake := PaletteStuff;
  219.    for Count := 63 downto 0 do
  220.        begin
  221.        Port[$3C8] := 0;
  222.        PaletteStuff := PalToMake;
  223.        Delay(5);
  224.        for ColorOn := 0 to 15 do
  225.            begin
  226.            PaletteStuff[ColorOn, 0] := (PaletteStuff[ColorOn, 0] * Count) div 63;
  227.            PaletteStuff[ColorOn, 1] := (PaletteStuff[ColorOn, 1] * Count) div 63;
  228.            PaletteStuff[ColorOn, 2] := (PaletteStuff[ColorOn, 2] * Count) div 63;
  229.            Port[$3C9] := PaletteStuff[ColorOn, 0];
  230.            Port[$3C9] := PaletteStuff[ColorOn, 1];
  231.            Port[$3C9] := PaletteStuff[ColorOn, 2];
  232.            end;
  233.        end;
  234.    end;
  235.  
  236. procedure FadeInScreen16;
  237.    var
  238.      Count        : byte;
  239.      ColorOn      : byte;
  240.      PaletteStuff : Palette16;
  241.      FastPal      : Palette16;
  242.  
  243.    begin
  244.    GetVGAPalette16(PaletteStuff);
  245.    for Count := 0 to 63 do
  246.        begin
  247.        Port[$3C8] := 0;
  248.        PaletteStuff := PalToMake;
  249.        Delay(5);
  250.        for ColorOn := 0 to 15 do
  251.            begin
  252.            PaletteStuff[ColorOn, 0] := (PaletteStuff[ColorOn, 0] * Count) div 63;
  253.            PaletteStuff[ColorOn, 1] := (PaletteStuff[ColorOn, 1] * Count) div 63;
  254.            PaletteStuff[ColorOn, 2] := (PaletteStuff[ColorOn, 2] * Count) div 63;
  255.            Port[$3C9] := PaletteStuff[ColorOn, 0];
  256.            Port[$3C9] := PaletteStuff[ColorOn, 1];
  257.            Port[$3C9] := PaletteStuff[ColorOn, 2];
  258.            end;
  259.        end;
  260.    end;
  261.  
  262. end.
  263.  
  264.